package com.chenjun.core.service.sys.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.chenjun.common.model.DataGridModel;
import com.chenjun.core.dao.generator.entity.SysUserGroup;
import com.chenjun.core.dao.generator.mapper.SysUserGroupMapper;
import com.chenjun.core.dao.module.SysUserGroupRelationMapper;
import com.chenjun.core.service.sys.SysUserGroupService;

@Service
@Transactional
public class SysUserGroupServiceImpl implements SysUserGroupService {
	
	@Autowired
	private SysUserGroupMapper sysUserGroupMapper;
	
	@Autowired
	private SysUserGroupRelationMapper sysUserGroupRelationMapper;
	
	@Override
	public SysUserGroup get(String id) {
		return sysUserGroupMapper.selectByPrimaryKey(id);
	}

	@Override
	public int create(SysUserGroup record) {
		return sysUserGroupMapper.insert(record);
	}

	@Override
	public int delete(String id) {
		return sysUserGroupMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int update(SysUserGroup record) {
		return sysUserGroupMapper.updateByPrimaryKey(record);
	}

	@Override
	public int createOrUpdate(SysUserGroup record) {
		int rows = 0;
		if (StringUtils.isBlank(record.getId())) {
			rows = sysUserGroupMapper.insert(record);
		} else {
			rows = sysUserGroupMapper.updateByPrimaryKeySelective(record);
		}
		return rows;
	}

	@Override
	public List<SysUserGroup> doListByCondition(DataGridModel param) {
		return sysUserGroupRelationMapper.selectByCondition(param);
	}

	@Override
	public int deleteByCondition(Map<String, String> params) {
		return sysUserGroupRelationMapper.deleteByCondition(params);
	}

}
